<?php
class file_upload_model extends MY_model
{
    public $id;
    public $file_title;
    public $file_title_vi;
    public $file_url;
    public $file_url_thumb;
    public $embed_link;
    public $sort_order;
    public $type;
    public $modified_date;
    public static $video = "VIDEO";
    public static $IMG = "IMG";
    public static $LOGO = "LOGO";

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM file_upload");
        return $this->to_domain_models($query->result());
    }

    public function get_elements_by_type($type)
    {
        $query = $this->db->query("SELECT * FROM file_upload WHERE type LIKE ?", array('%' .$type . '%'));
        return $this->to_domain_models($query->result());
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM file_upload WHERE id = ?",array($id));
        return $this->to_domain_model($query->row());
    }

    public function get_all_video()
    {
        $query = $this->db->query("SELECT * FROM file_upload where 'type' like '%VIDEO%' ");
        return $this->to_domain_models($query->result());
    }

    public function get_all_image()
    {
        $query = $this->db->query("SELECT * FROM file_upload where type LIKE '%IMG%'");
        return $this->to_domain_models($query->result());
    }



//    public function insertEmail($data)
//    {
//        $this->db->insert("email",$data);
//    }

    // -------------------------------------------------------------------------------- PRIVATE METHOD

    // Private method
    public function to_domain_model($item)
    {
        $model = new file_upload_model();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->file_title = isset($item->file_title) ? $item->file_title : '' ;
        $model->file_title_vi = isset($item->file_title_vi) ? $item->file_title_vi : '' ;
        $model->file_url = isset($item->file_url) ? $item->file_url : '';
        $model->file_url_thumb = isset($item->file_url_thumb) ? $item->file_url_thumb : '';
        $model->embed_link = isset($item->embed_link) ? $item->embed_link : '';
        $model->sort_order = isset($item->sort_order) ? $item->sort_order : '';
        $model->type = isset($item->type) ? $item->type : '';

        $model->modified_date = isset($item->modified_date) ? $item->modified_date: '';
        return $model;
    }
}